import { post, remove, get, put } from './api'
import Vue from 'vue'
// import { read } from '../store/modules/init.js'
//查询单个员工信息
export const getUserApi = (id) => {
    const url = '/usermgt/employee/' + id
    return get(url)
}

export const getUpLoadApi = (newPer) => {
    const url = '/usermgt/employee/1'
    const body = {
        method: 'updateAvatar',
        avatarPicture: newPer
    }
    return put(url, body)
}

// 修改单个员工信息
export const putUserApi = (fd,per,ids) => {
    let obj = {
        id: ids,
        employeeName: per.employeeName,
        nickName: per.nickName,
        gender: per.gender,
        email: per.email,
        contact: per.contact,
        rtx: per.rtx,
        entryTime: per.entryTime,
        birthdate: per.birthdate,
        status: per.status,
        /*avatar: per.avatar,*/
        orgStructId: per.orgStructId,
        orgFuncIds: per.orgFuncIds
    }
    fd.append('args',JSON.stringify(obj))
    fd.append('method','editPerson')
   /* const body = {
        method: 'update',
        args: fd
    }*/
    /*const url = '/usermgt/employee/' + id*/
    const url = '/usermgt/employee/form'
    /*const url = '/usermgt/employee/update/' + id*/
    return  Vue.http.post(url, fd, {timeout: 10000},).then((resp) => {
        if (resp.status !== 200) {
            return Promise.reject(resp)
        }
        if (_.isString(resp.body)) {
            try {
                resp.body = JSON.parse(resp.body)
            } catch (err) {
                console.log('rpcCall exception')
                console.log(err)
                resp.body = err
                resp.body.result = { errno: -1 }
            }
        }
        return resp
    })
}

//获取个人资料
export const getUserPersonalData = (args) => {
    const url = '/usermgt/employee'
    const body = {
        method: 'getPersonalData'
    }
    return post(url, body)
}
